package org.gienah.testing.junit;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Santiago L. Valdarrama
 * @since E0.1
 */
public class ConfigurationException
		extends Exception {

	private static final long serialVersionUID = 1761654135254859818L;

	public final static int ERROR_CODE_MISSING_CONFIGURATION = 1;
	public final static int ERROR_CODE_MISSING_CONFIGURATION_LOCATIONS = 2;
	public final static int ERROR_CODE_PROVIDER_CYCLIC_REFERENCE = 3;
	public final static int ERROR_CODE_INVALID_CONTEXT_LOADER = 4;
	public final static int ERROR_CODE_INVALID_CONTEXT = 5;

	public static Map<Integer, String> codeMessageMap;

	private final int code;

	static {
		ConfigurationException.codeMessageMap = new HashMap<Integer, String>();
		ConfigurationException.codeMessageMap.put(ERROR_CODE_MISSING_CONFIGURATION, "Test class doesn't define proper configuration metadata");
		ConfigurationException.codeMessageMap.put(ERROR_CODE_MISSING_CONFIGURATION_LOCATIONS, "The configuration locations information couldn't be determined");
		ConfigurationException.codeMessageMap.put(ERROR_CODE_PROVIDER_CYCLIC_REFERENCE, "There is a cyclic reference between defined configuration providers");
		ConfigurationException.codeMessageMap.put(ERROR_CODE_INVALID_CONTEXT_LOADER, "Defined context loader couldn't be instantiated");
		ConfigurationException.codeMessageMap.put(ERROR_CODE_INVALID_CONTEXT, "The context object returned from the context loader is not valid");
	}

	public ConfigurationException(final int code) {
		super(ConfigurationException.codeMessageMap.get(code));
		this.code = code;
	}

	public ConfigurationException(final int code, final Throwable t) {
		super(ConfigurationException.codeMessageMap.get(code), t);
		this.code = code;
	}

	public int getCode() {
		return this.code;
	}

}
